package com.example.ecs.components.physics;

import com.example.ecs.core.Component;

/**
 * SATCollisionComponent类表示实体的SAT碰撞组件
 * 包含用于SAT碰撞检测的多边形顶点
 */
public class SATCollisionComponent extends Component {
    public double[][] vertices; // 多边形顶点 [[x1,y1], [x2,y2], ...]
    public boolean solid = true; // 是否为固体，可以与其他实体碰撞
    
    public SATCollisionComponent(double[][] vertices) {
        this.vertices = vertices;
    }
    
    /**
     * 获取多边形的边向量
     * @return 边向量数组
     */
    public double[][] getEdges() {
        int numVertices = vertices.length;
        double[][] edges = new double[numVertices][2];
        
        for (int i = 0; i < numVertices; i++) {
            int next = (i + 1) % numVertices;
            edges[i][0] = vertices[next][0] - vertices[i][0];
            edges[i][1] = vertices[next][1] - vertices[i][1];
        }
        
        return edges;
    }
}